#include "nr_core.h"
#include "nr_device_export.h"
#include "nr_device_nport.h"
#include "nr_device_apmd7xx.h"

nr_error_t nr_create_device(nr_id_t device_type_id, void **p_device)
{
    // Support the nport and apmd7xx device at the same time
    Q_ASSERT(p_device);
    if (device_type_id == NR_DEVICE_TYPE_ID_NPORT)
    {
        nr_device_nport* nport = new nr_device_nport;
        *p_device = nport;

        return NR_ERROR_NONE;
    }
    else if (device_type_id == NR_DEVICE_TYPE_ID_APMD7XX)
    {
        nr_device_apmd7xx* apmd7xx = new nr_device_apmd7xx;
        *p_device = apmd7xx;
        
        return NR_ERROR_NONE;
    }
    else
        return NR_ERROR_NOT_SUPPORT;
}

nr_error_t nr_free_device(void *device)
{
    if(device == NULL)
        return NR_ERROR_NOT_VALID_PARAMETER;
    
    nr_device* device_obj = static_cast<nr_device*>(device);
    delete device_obj;
    
    return NR_ERROR_NONE;
}